<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/plugins/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="/build/css/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="/css/my-style.css">
</head>
<body>
<!-- 弹框content -->
<div id="modal-content1" style="padding:20px;">
    <form class="layui-form" action="">
        <input type="hidden" id="deptId" th:value="${dept.getId()}">
        <div class="layui-form-item">
            <label class="layui-form-label">部门名<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <div class="layui-input-block" style="    margin-left: 0px; ">
                    <input type="text"  lay-filter="tree" class="layui-input"name="deptName" lay-verify="required" th:value="${dept.getDeptName()}">
                    <!--<input type="text" id="parentId"  hidden name="parentId" >-->

                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="orderNum" required lay-verify="required"
                       placeholder="请输入排列顺序"
                       autocomplete="off" class="layui-input"
                       oninput="value=value.replace(/[^\d]/g,'')"
                       th:value="${dept.getOrderNum()}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">负责人<span
                    style="color: red">★</span>：</label>
            <div class="layui-input-block">
                <input type="text" name="leader" required lay-verify="required"
                       placeholder="请输入负责人"
                       autocomplete="off" class="layui-input"
                       th:value="${dept.getLeader()}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">联系电话：</label>
            <div class="layui-input-block">
                <input type="text" name="phone"
                       placeholder="请输入电话号码"
                       autocomplete="off" class="layui-input"
                       th:value="${dept.getPhone()}">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮件地址：</label>
            <div class="layui-input-block">
                <input type="text" name="email"
                       placeholder="请输入email"
                       autocomplete="off" class="layui-input"
                       th:value="${dept.getEmail()}">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="/plugins/layui/layui.js"></script>
<script>
    // 增加项目表单
    layui.use(['form', 'layedit', 'laydate', 'jquery'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //常规用法
        laydate.render({
            elem: '#startDate'
        });
        laydate.render({
            elem: '#endDate'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            title: function (value) {
                if (value.length < 5) {
                    return '标题至少得5个字符';
                }
            }
            , pass: [/(.+){6,12}$/, '密码必须6到12位']
            , content: function (value) {
                layedit.sync(editIndex);
            }
        });

        //监听指定开关
        form.on('switch(switchStatus)', function (data) {
            this.value = this.checked ? "0" : "1";
        });

        var $ = layui.$;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            console.log(data.field);
            $.ajax({
                type: 'PUT',
                url: "/system/dept/update/" + $("#deptId").val(),
                data: data.field,
                success: function (res) {
                    // console.log(res);
                    // layer.closeAll();
                    if (res.code == 0) {
                        layer.msg("修改成功",{
                            time: 800
                        },function () {
                            // 关闭自己
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                            window.parent.location = "/system/dept/view";//页面刷新
                        });
                    } else {
                        layer.msg("修改失败" + res.msg);
                    }
                }
            });

            return false;

        });
    });
</script>

<script>

</script>
<script>

</script>
</body>
</html>